
package connection;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;


public class ConnectionControl{
  
	private  String className = "oracle.jdbc.driver.OracleDriver";
	private  String userName = "system";
	private String password = "ceserye";
	private String url = "jdbc:oracle:thin:@//127.0.0.1:1521/xe";
	private static ConnectionControl connInstance = null;

	protected Connection connection;
	
  public static synchronized ConnectionControl getInstance() {
	if(connInstance == null) {
	  connInstance = new ConnectionControl(); 		
	}
	return connInstance;
  }
 
  //to open a connection to database
  public Connection getConnection(){
	  
	  Connection conn = null;
	  try {
		  Class.forName(className);
		  conn = DriverManager.getConnection (url, userName, password);
		  //System.out.println("Connection Established");
	  }  catch (ClassNotFoundException e) {
		  e.printStackTrace();
	  }	 catch (SQLException e) {
		  e.printStackTrace();
	  }
	  return conn;
  }

  //to close the connection
  public void closeConnection(Connection conn){
	  try {
		  conn.close();
	  } catch (SQLException e) {
		  e.printStackTrace();
	  }
  } 
 
}
